package com.nf.health.app.main_intervention.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.nf.health.app.R;
import com.nf.health.app.main_intervention.bean.MedicinedDietBean;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by he_pan on 2016/11/24.
 * The only genius that is worth anything is the genius for hard work
 *
 * @author he_pan
 * @Description 原料
 */

public class GvYuanLiaoAdapter extends BaseAdapter {
    private Context ctx;
    private String amount;
    private String[] splitAmount;

    public GvYuanLiaoAdapter(Context ctx, MedicinedDietBean mDietBean) {
        this.ctx = ctx;
        this.amount = mDietBean.getAmount();
        splitAmount = amount.split("\\|\\|");
    }

    @Override
    public int getCount() {
        int length = splitAmount.length;
        if (length % 2 == 0) {
            return length / 2;
        } else {
            return length / 2 + 1;
        }
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        int left = position * 2;
        int right = position * 2 + 1;
        MyViewHolder holder;
        convertView = View.inflate(ctx, R.layout.item_yuan_liao, null);
        holder = new MyViewHolder(convertView);
        convertView.setTag(holder);
        if (left < splitAmount.length) {
            holder.tvLeft.setText(splitAmount[left]);
        }
        if (right < splitAmount.length) {
            holder.tvRight.setText(splitAmount[right]);
        }

        return convertView;
    }


    class MyViewHolder {
        @Bind(R.id.tv_left)
        TextView tvLeft;
        @Bind(R.id.tv_right)
        TextView tvRight;

        MyViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
